package com.hanlin.backend.common.error;

import org.apache.commons.lang3.StringUtils;

/**
 * 异常枚举类
 *
 * @author:hl.yuan
 * @date:2021-01-06
 */
public enum ErrorCodeEnum {

    SYS_ERROR("500", "系统错误，请重试"),
    UNKNOWN_ERROR("100", "未知的系统异常"),
    SERVICE_INVOKE_FAIL("101", "服务调用失败"),
    ILLEGAL_ARGS("102", "参数校验错误"),
    No_TOKEN("401", "会话已失效，请重新登录"),
    NO_AUTHORITY("403", "无权限，非法访问"),
    NO_RESOURCE("404", "无效链接"),
    ;

    public static ErrorCodeEnum getByValue(String code) {
        for (ErrorCodeEnum result : values()) {
            System.out.println(result.ordinal());
            if (StringUtils.equals(result.getCode(), code)) {
                return result;
            }
        }
        return null;
    }

    /**
     * 结果码值.
     */
    private String code;
    /**
     * 描述.
     */
    private String desc;

    ErrorCodeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
